import { _decorator } from "cc";
import LevelColler from "../../MainScene/Script/LevelColler";
import Action3dManager, { ActionMngType } from "../../Script/Common/Action3dManager";
import { EventType } from "../../Script/GameSpecial/GameEventType";
import { GlobalEnum } from "../../Script/GameSpecial/GlobalEnum";
import { Role } from "./Role";

const { ccclass, property } = _decorator;

/**敌人 */
@ccclass('Enemy')
export class Enemy extends Role {
    /**************************************************对外功能**************************************************/
    /**被击 */
    public beHit(atkRole: Role) {
        if (atkRole.isPlayer) {
            this.emit(EventType.LevelEvent.dropGold, { p: this.node.position, count: 10 });
        }

        Action3dManager.getMng(ActionMngType.Level).stopAllActions(this.node);
        this.exitLevel();
        this.isAlive = false;
        // switch (atkRole.weaponType) {
        //     case GlobalEnum.WeaponType.captain:
        //     case GlobalEnum.WeaponType.gun:
        //     case GlobalEnum.WeaponType.hunter: {
        //         let str = "RoleDeadAnim";
        //         let p = atkRole.node.position;
        //         let r = Math.atan2(p.z - this.node.position.z, this.node.position.x - p.x);
        //         this.emit(EventType.LevelEvent.addDeadBody, { p: this.node.position, radian: r, scale: this.roleScale, isPlayer: false, skin: this.skinId, anim: str });
        //         break;
        //     }
        //     default: {
        //     }
        // }
        this.emit(EventType.LevelEvent.addDeadBody, { p: this.node.position, radian: this.faceRadian, scale: this.roleScale, isPlayer: false, skin: this.skinId });
        this.emit(EventType.LevelEvent.enemyDead, this);
    }
    /**成功击中目标 */
    public hitSuccess(target: LevelColler) {
        let type = target.collerType;
        switch (type) {
            case GlobalEnum.CollerType.barrier: {
                break;
            }
            case GlobalEnum.CollerType.role: {
                this.emit(EventType.LevelEvent.killOneRole, this);
                this.growUpRoleScale();
                break;
            }
        }
    }

    protected onAnimFinish() {
        let cb = this.animFinishCb;
        this.animFinishCb = null;
        if (!!cb) {
            cb();
        }
        switch (this.curAnimClip) {
            case GlobalEnum.RoleAnimType.atk: {
                // if (this.leftWeapon) {
                //     this.leftWeapon.atkFinish();
                // }
                // this.rightWeapon.atkFinish();
                // if (this.customUpdateState == GlobalEnum.RoleState.atking) {
                this.enterCustomUpdateState(GlobalEnum.RoleState.move);
                this.emit(EventType.LevelEvent.enemyAtkFinish, this);
                // }
                break;
            }
        }
    }

}
